﻿using System;

namespace AgFractal.Fractals
{
    public class Julia : AbstractFractal
    {
        public Julia()
        {
            ID = new Guid("43103176-B193-4536-AA85-0F8226404D99");
            Name = Description = "Julia";
            R1 = -2.25; I1 = 1.5; R2 = 2.25; I2 = -1.5;

            var cParam = new FractalParameter { Name = "c", ComplexValue = c };
            cParam.PropertyChanged += (s, e) => c = cParam.ComplexValue;
            parameter.Add(cParam);
        }

        private Complex c = new Complex(-0.771, 0.115);
        protected override short Calculate(double r, double i, short MaxIteration)
        {
            Complex z = new Complex(r, i);
            short j;
            for (j = 0; j < MaxIteration; j++)
            {
                if (z.Abs2() > 4) break;
                z = z.Sqr() + c;
            }
            return j;
        }
    }
}